<?php 
//Security Checking for the user if allowed to login.
session_start();
if(strlen($_SESSION['u_name'])==0)
{
	?>
	<script>
	window.open("admin-login.php","_self");
	</script>
	<?php 
	exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
.body {
	background-color:#a6bf79;
	color:#000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	margin: 10px 10px 10px 10px;
	padding: 0px;
}
.textLike
{
	color:#000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	padding: 0px;
}
</style>
<title>Admin -HomePage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="../js/jquery-1.4.2.js" type="text/javascript" language="javascript"></script>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<link href="../css/menu.css" rel="stylesheet" type="text/css" />
<!--<script type="text/javascript" src="../js/jquery.tablesorter.js"></script>-->
<script type="text/javascript" src="../js/sorttable/sorttable.js"></script> 
</head>
<body class="body">
<div id="body" style="width:960px;">
<div align="center">
<!-- Admin Home Page Menu Bar -->

<ul id="list-nav">
<li><a href="admin-homepage.php">Home</a></li>
<li><a href="admin-homepage.php">All Listings</a></li>
<!--<li><a href="approved-listing.php">Approved Listing</a></li>-->
<li><a href="unapproved-listing.php">Deactivated Listing</a></li>
<li><a href="new-listing.php">New Lists</a></li>
<li><a href="admin-themelist.php">Theme List</a></li>
<li><a href="secure.php?logout=yes">Log Out</a></li>
</ul>


<!-- Menu Bar Ends -->
</div>
<br />

<?php 
/*
 * Summary : Created By Avik on 18th April,2010
 * Version : 1.0
 * Contents: This file Shows All the data Admin Home page
 * Chnages
 */

#===========AUTHENTICATION========================#
//session_start();
if(empty($_SESSION['u_name']))
{
	header("Location:admin-login.php");
}
//#########INCLUDE FILES########
include_once '../conf/db-config.php';
include_once '../conf/error.php';
include_once '../clsFetchData.php';
include_once '../array_to_xml.php';
include_once 'city-name.php';
include_once '../submitemail.php';
//##############################

$objFetchData = new clsFetchData();
$arrAllUnApprovedDataToShow = array();
$userid = $_SESSION['user_id'];	

$arrCity = $objFetchData->fetchCityForUser($userid);
unset($arrAllUnApprovedDataToShow);
if(strtoupper($_SESSION['is_admin'])=='Y')
{
	$arrAllUnApprovedDataToShow  = $objFetchData->FetchDataToArray('y');
}
else
{
	if(count($arrCity)>0)
		$arrAllUnApprovedDataToShow  = $objFetchData->FetchDataToArrayWithCategories('y',$arrCity);
}
$heading = "Showing Approved Listings";


 
?>
<h3 style="padding-left: 50px;padding-bottom: 10px;"><u><i><?php echo $heading; ?></i></u></h3>
<table cellpadding="0" cellspacing="10" border="0" width="470" style="padding-left: 50px;padding-right: 50px;" align="right">
<tr>
		<td height="20px" align="right" style="padding-right: 0px;" >
			<a href="changepassword.php">Change Password</a>
		</td>
		<?php if(strtoupper($_SESSION['is_admin'])=='Y') {  ?>
<!--		<td height="20px" align="right" style="padding-right: 5px;">-->
<!--			<a href="assign-city">Add City</a>-->
<!--		</td>-->
		<td height="20px" align="right" style="padding-right: 5px;">
			<a href="assign-user.php">Add/Assign User</a>
		</td>
		<?php } ?>
	</tr>
	</table>
<?php 

/*
 * SHOW ALL UNAPPROVED DATA LISTINGS
 */

if($_SESSION['is_admin']=="Y")
{
	$style = 'style="height: 600px;overflow:scroll;width:950px;"';
}
else
{
	$style = 'style="margin-top:25px;margin-left:25px;"';
}
?>
<div <?php echo $style; ?>>
<?php 
if(is_array($arrAllUnApprovedDataToShow) && count($arrAllUnApprovedDataToShow)>0)
{
	?>
	
	<table cellpadding="0" cellspacing="10" border="0" width="870" align="center">
	<tr>
	<td>
	<table cellpadding="0" cellspacing="0" class="sorttable" width="870" border="0" align="center" id="inboxMessage">
		<thead>
		<tr height="30" style="background-color: #615B5B;color: #FFF;">
			<td width="70" align="center">
			SL. No.
			</td>
			<td width="300" align="center">
			<span style="color: #FFF;text-decoration: none;font-weight: normal;cursor: pointer;">Business Listing Title</span>
			</td>
			<td width="200" align="center">
			<span style="color: #FFF;text-decoration: none;font-weight:normal;cursor: pointer;">Unique ID</span>
			</td>
			<td width="100" align="center">
			<span style="color: #FFF;text-decoration: none;font-weight: normal;cursor: pointer;">Category</span>
			</td>
			<td align="center" width="130">
				<span style="color: #FFF;text-decoration: none;font-weight: normal;cursor: pointer;">Status</span>
			</td>
			<td align="center" width="130">
				<span style="color: #FFF;text-decoration: none;font-weight: normal;cursor: pointer;">Actions</span>
			</td>
		</tr>
		</thead>
		<tbody>
	<?php 
	$icount=0;
	foreach ($arrAllUnApprovedDataToShow as $arrData)
	{
		if(($icount%2)==1)
		{
			$style="style='background-color: #0B6E96;color: #FFF;'";
		}
		else
		{
			$style="style='background-color: #4F97B3;color: #FFF;'";
		}
		?>
		
		<tr height="25" <?php echo $style; ?>>
			<td width="60" align="center">
			<?php echo $arrData['sl_no']; ?>
			</td>
			<td width="300" align="center">
			<span style="color: #FFF;text-decoration: none;font-weight: normal;cursor: pointer;"><a style="color: #FFF" onclick="showBig('<?php echo $arrData['id']; ?>')"><?php echo $arrData['business_title']; ?></a></span>
			</td>
			<td width="200" align="center">
			<span style="color: #FFF;text-decoration: none;font-weight: normal;cursor: pointer;"><?php echo $arrData['id']; ?></span>
			</td>
			<td width="100" align="center">
			<span style="color: #FFF;text-decoration: none;font-weight:normal;cursor: pointer;"><?php echo $arrData['theme']; ?></span>
			</td>
			<td align="center" width="130">
				<span style="color: #FFF;text-decoration: none;font-weight: normal;"><?php if($arrData['is_approved']=="y") { echo " Approved " ; }else if($arrData['is_approved']=="n") { echo "Not Approved"; } else { echo "No Action Taken Yet";} ?></span>
			</td>
			<td width="130" align="center">
			<span style="color: #FFF;text-decoration: none;font-weight: normal;cursor: pointer;"><a style="color: #FFF" onclick="showBig('<?php echo $arrData['sl_no']; ?>')">Show </a>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
			<span style="color: #FFF;text-decoration: none;font-weight: normal;cursor: pointer;"><a style="color: #FFF" onclick="triggerMail('<?php echo $arrData['sl_no']; ?>')">Email</a></span>
			</td>
		</tr>		
		<?php
		$icount++; 
		}
		?>
		</tbody>
		</table>
		</td>
		</tr>
	</table>
	<?php 
}
else
{
	?>
	<table cellpadding="0" cellspacing="0" width="100%" align="center" height="200">
		<tr>
			<td align="center" valign="bottom">
				No New Data Found
			</td>	
		</tr>
	</table>
	<?php 
}
?>
</div>

<div style="height: 20px;">&nbsp;</div>
<?php if($_SESSION['is_admin']=="Y") { ?>
<div>

<table id="myTable2" cellpadding="0" cellspacing="0" width="100%" align="center" class="sorttable" >
<thead>
<tr height="30" style="background-color: #615B5B;color: #FFF;">
	<td align="center" width="200">User Name </td>
	<td align="center" width="500">Assigned City(s)</td>
	<td align="center" width="250">Actions</td>		
</tr>
</thead>
<tbody>
	<?php 
	
	$arrUsers = array();
	$arrUsers = $objFetchData->getAllUsersCity();
	
	$icount=0;
	foreach ($arrUsers as $val)
	{
		if(($icount%2)==1)
		{
			$style="style='background-color: #0B6E96;color: #FFF;'";
		}
		else
		{
			$style="style='background-color: #4F97B3;color: #FFF;'";
		}
	$icount++;
	?>
	<tr height="25" <?php echo $style; ?>>
	<td align="center"><?php echo $val['user_name']; ?></td>
	<td align="center"><?php echo $val['city']; ?></td>
	<td align="center">
		<a onclick="javascript:window.open('assign-user.php?uid=<?php echo $val['user_id']; ?>','_self');" style="cursor: pointer;">Edit User</a>&nbsp;|&nbsp; 
		<a onclick="javascript:window.open('delete-user-city.php?uid=<?php echo $val['user_id']; ?>','_self');" style="cursor: pointer;">Delete User</a>
	</td>		
	</tr>
	<?php 
	}
	?>
</tbody>
</table>
</div>
<?php } ?>

<?php 


/*
 * XML REGENARATE WHEN FIND APPROVED
 */

if($_REQUEST['generate']=="yes")
{

  	//$admin_mail_id = "listings@globaltodo.com";
  	
  	//$newMsg = GENERATE_SMTP_MAIL($admin_mail_id,$admin_mail_id,"GlobalToDo",'','','A New Listing is waiting for your Approval','A New Listing is waiting for your Approval');
  	//print $newMsg;
  	$message = "success";
  
	$arrApprovedDataToShow = array();
	$arrApprovedDataToShow  = $objFetchData->FetchDataToArray('y');
	array_to_xml($arrApprovedDataToShow,1);
	array_to_xml_mobile_app($arrApprovedDataToShow,1);	
}

?>
<script type="text/javascript">

	function editThis(id)
	{
		if(confirm("Do you really want to Edit this listing?"))
		{
			window.open('editListing.php?id='+id,'_self');
		}
		else
		{
			return false;
		}
	}

	function approveThis(id,city,state)
	{
		var random = (Math.random()*10000001);
		if(confirm("Do you really want to approve this ?"))
		{
			$.post("approveListing.php",{id:id,city:city,state:state},function(data)
					{
						if(data==1)
						{
							window.open("admin-homepage.php?rand="+random+"&generate=yes","_self");
							//window.location.reload();
						}
						else
						{
							alert("There was a problem is saving. Please try later. Thank you");
						}
					},"text");
		}
	}

	function deactivateThis(id)
	{
		if(confirm("Do you really want to deactivate this ?"))
		{
			$.post("deactivateListing.php",{id:id},function(data)
					{
						if(data==1)
						{
							window.open("admin-homepage.php?rand="+random+"&generate=yes","_self");
							//window.location.reload();
						}
						else
						{
							alert("There was a problem is saving. Please try later. Thank you");
						}
					},"text");
		}
	}

	function deleteThis(id)
	{
		if(confirm("Do you really want to delete this ?"))
		{
			$.post("deleteListing.php",{id:id},function(data)
					{
						if(data==1)
						{
							window.open("admin-homepage.php?rand="+random+"&generate=yes","_self");
						}
						else
						{
							alert("There was a problem is saving. Please try later. Thank you");
						}
					},"text");
		}
	}

	function showBig(id)
	{
		//document.getElementById(id).style.display="block";
		var URL  = "show-hide-listings.php?id="+id;
		window.open(URL,"_self");
		
	}
	function triggerMail(id)
	{
		var w=500;
		var h=250;
		var pageURL = "http://www.globaltodo.com/xmlcontact/admin/pop-up-extra-email.php?id="+id;
	    //window.open("http://localhost/xmlcontact/admin/pop-up-extra-email.php","");
	    var title = "Additional Email Sent Box";
	    var left = (screen.width/2)-(w/2);
	    var top = (screen.height/2)-(h/2);
	    var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
		
	}

	if(document.getElementById('inboxMessage'))
	{
		var table = document.getElementById('inboxMessage');
		sorttable.makeSortable(table);
	}

	if(document.getElementById('myTable2'))
	{
		var table = document.getElementById('myTable2');
		sorttable.makeSortable(table);
	}
</script>

</div>
</body>
</html>